﻿using CN;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace ProyectoSalvadorDelMundo.Helpers
{
    /// <summary>
    /// Summary description for ImageHandler
    /// </summary>
    public class ImageHandler : IHttpHandler 
    {

        public void ProcessRequest(HttpContext context)
        {
            //context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");
            Int64 ImgId;
            if (context.Request.QueryString["id"] !=null )
            {
                ImgId = Convert.ToInt64(context.Request.QueryString["id"]);
                Servidores oCnServidores = new Servidores();
                byte[] byteImg = oCnServidores.Imagen(ImgId);
                if (oCnServidores.Imagen(ImgId) != null)
                {
                    try
                    {
                        context.Response.BinaryWrite(byteImg);
                    }
                    catch
                    {
                        // Retornar imagen default.
                    }
                    
                }           
            }
        }

        public bool IsReusable  
        {
            get
            {
                return false;
            }
        }
    }
}